/**
 * Copyright &copy; 2018 peanut.ai All rights reserved.
 */
package ai.peanut.selfbase.common.utils;

import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.google.common.collect.Maps;
import org.springframework.core.io.DefaultResourceLoader;

import java.io.File;
import java.io.IOException;
import java.util.Map;

/**
 * 全局配置类
 * @author
 * @version
 */
public class Global {

	/**
	 * 当前对象实例
	 */
	private static Global global = new Global();
	
	/**
	 * 保存全局属性值
	 */
	private static Map<String, String> map = Maps.newHashMap();
	
	/**
	 * 属性文件加载对象
	 */
	private static PropertiesLoader loader = new PropertiesLoader("init.properties");


	
	/**
	 * 获取当前对象实例
	 */
	public static Global getInstance() {
		return global;
	}
	
	/**
	 * 获取配置
	 */
	public static String getConfig(String key) {
		String value = map.get(key);
		if (value == null){
			value = loader.getProperty(key);
			map.put(key, value != null ? value : StringUtils.EMPTY);
		}
		return value;
	}



	public static boolean getAPIDebug(){
		String debug =  getConfig("api_debug");
		return debug.equalsIgnoreCase("true");
	}

	public static Long getSessionTimeout(){
		String sessionTimeout =  getConfig("sessionTimeout");
		return  Long.parseLong(sessionTimeout);
	}


	/**
	 * 获取URL后缀
	 */
	public static String getUrlSuffix() {
		return getConfig("urlSuffix");
	}

}
